var t = function(t) {
    return t && t.__esModule ? t : {
      default: t
    };
  }(),
  app = getApp(),
  e = 0;
var page = 1;
Page({
  data: {
    curHdIndex: 1,
    index: 5,
    pageOne: 0,
    pageTwo: 0,
    prenumber: 20,
    tsid: 1,
    loadingBoo: !0,
    moreBooOne: !0,
    moreBooTwo: !0,
    communityListOne: [],
    communityListTwo: [],
    url: "patient/community/list/",
    oneBoo: !1,
    twoBoo: !1,
    mask: !0,
    currindex: 0,
    itemList: [],
    ismore: true,
    bigMask:false,
    consulList: [
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
    ]
  },
  //tab切换
  list: function(e) {
    var that = this;
    console.log(e)
    if (e.currentTarget.dataset.id == 1) {
      console.log('123')
      that.setData({
        curHdIndex: 1
      })
    } else {
      //热门
      that.setData({
        curHdIndex: 2
      })
    }
    if (e.currentTarget.dataset.id == 2) {
      app.util.request({
        url: 'entry/wxapp/share.remen',
        data: {
          openid: wx.getStorageSync('openid'),
          state: 0
        },
        success: function(res) {
          console.log(res)
          that.setData({
            communityListOne: res.data,
          })
        }
      })
    } else {
      this.getAllshare()
    }
  },
  //上来加载
  // moreState: function() {
  //   var a = this,
  //     e = {
  //       type: a.data.curHdIndex,
  //       tsid: a.data.tsid,
  //       token: a.data.token
  //     },
  //     n = a.data.prenumber;
  //   t.default.getCommunityList(a, e, n);
  // },
  //点赞
  toLike: function(a) {
    var e = this;
    let communityListOne = e.data.communityListOne;
    var n = a.currentTarget.dataset.index
    var a_id = a.currentTarget.dataset.a_id
    var openid = wx.getStorageSync('openid')
    if (communityListOne[n].dianzan == 0) {
      app.util.request({
        'url': 'entry/wxapp/share.userdianz',
        data: {
          parentid: a_id,
          openid: openid,
        },
        success: function(res) {
          console.log(res)

        }
      })
      wx.showToast({
        title: "点赞成功",
        icon: "none",
        duration: 1500,
        success: function() {
          var dianzan = "communityListOne[" + n + "].dianzan"
          console.log(dianzan)
          e.setData({
            [dianzan]: 1
          })
        }
      });

    } else {
      wx.showToast({
        title: "点赞是严肃的，不可以反悔哦！",
        icon: "none",
        duration: 1500
      });
    }
  },
  searchbtn() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/search/search',
    })
  },
  dymore(){
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/dynamic/dynamic',
    })
  },

  onLoad: function(t) {
    var a = this;
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    a.setData({
      bgc: bgc
    })
    page = 1;
    a.getAllshare(page);
  },
  onReady: function() {},
  onShow: function() {
    var that = this
    var openid = wx.getStorageSync('openid')
    console.log(openid)
    if (openid) {
      that.setData({
        bigMask: true
      })
    } else {
      that.setData({
        bigMask: false
      })
    }
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  //发表动态
  addCommunity: function() {
    wx.navigateTo({
      url: "/hyb_yl/userLife/pages/addDynamic/addDynamic"
    });
  },

  //查询所有分享
  getAllshare: function(_page) {
    var that = this
    app.util.request({
      url: 'entry/wxapp/share.allshare',
      data: {
        openid: wx.getStorageSync('openid'),
        page: _page,
        pagback: 5,
        state: 0
      },
      success: function(res) {
        console.log(res)
        if (res.data.length < 5) {
          that.setData({
            ismore: false
          })
        }
        var list_t = that.data.itemList;
        console.log(list_t)
        var len = res.data.length;
        for (var i = 0; i < len; i++) {
          list_t.push(res.data[i])
        }
        wx.hideLoading()
        that.setData({
          communityListOne: list_t,
          page: 1,
        })
      }
    })
  },
  previewImage: function(a) {
    var t = this;
    console.log(a)
    var i = a.currentTarget.dataset.index;
    var url = a.currentTarget.dataset.url
    var artrs = a.currentTarget.dataset.data
    console.log(i, url, artrs)
    wx.previewImage({
      current: url,
      urls: artrs
    });
  },
  scrolltolower() {
    var that = this
    console.log(that.data.ismore)
    if (that.data.ismore) {
      page++;
      console.log(page)
      that.getAllshare(page);
    }
  },
});